package demo.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import demo.common.Result;
import demo.entity.Question;
import demo.entity.School;
import demo.mapper.QuestionMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin(maxAge = 3600)
@RestController
@RequestMapping("/question")
public class QuestionController {
  @Resource
  QuestionMapper questionMapper;

//  @PostMapping
//  public Result<?> save(@RequestBody Question question){
//    questionMapper.insert(question);
//    return Result.success();
//  }

  @GetMapping
  public Result<?> findPage(
                            @RequestParam(defaultValue = "") String search) {
    LambdaQueryWrapper<Question> wrapper = Wrappers.<Question>lambdaQuery();
    if (StrUtil.isNotBlank(search)) {
      wrapper.like(Question::getQid, search);
    }
    Page<Question> userPage = questionMapper.selectPage(new Page<>(1,100), wrapper);
    return Result.success(userPage);
  }
//  public Result findAll(){
//    LambdaQueryWrapper<Question> wrapper = Wrappers.<Question>lambdaQuery();
//    List<Question> question = questionMapper.selectList(wrapper);
//    return Result.success(question);
//  }
}
